package br.com.Login.bean;

import java.io.Serializable;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;

import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

@Entity
public class User implements Serializable {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue
	private int cdUser;
	
	private String username;
	private String password;
	
	private Boolean ativo;
	
	@Column(name="troca_senha")
	private Boolean trocaSenha;
	
	@ManyToMany(cascade=CascadeType.MERGE)
    @JoinTable(name = "user_autorizacao", joinColumns = {@JoinColumn(name = "cdUser")}, inverseJoinColumns = {@JoinColumn(name = "cdAutorizacao")})
    @LazyCollection(LazyCollectionOption.FALSE)
   	private List<Autorizacao> autorizacoes;
	
	//Getters and Setters
	public int getCdUser() {
		return cdUser;
	}
	public void setCdUser(int cdUser) {
		this.cdUser = cdUser;
	}
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public Boolean getAtivo() {
		return ativo;
	}
	public void setAtivo(Boolean ativo) {
		this.ativo = ativo;
	}
	public List<Autorizacao> getAutorizacoes() {
		return autorizacoes;
	}
	public void setAutorizacoes(List<Autorizacao> autorizacoes) {
		this.autorizacoes = autorizacoes;
	}

	@Override
	public boolean equals(Object obj) {
		User u = (User) obj;
		
		if(this.username.equals(u.getUsername()) && this.password.equals(u.getPassword())){
			return true;
		}else
		return false;
	}
	
	@Override
	public int hashCode() {
		// TODO Auto-generated method stub
		return super.hashCode();
	}
	public Boolean getTrocaSenha() {
		return trocaSenha;
	}
	public void setTrocaSenha(Boolean trocaSenha) {
		this.trocaSenha = trocaSenha;
	}
}
